<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="common/include :: header('新增物品信息')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-statement-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">物品名称：</label>
            <div class="col-sm-8">
                <input name="goodsName" class="form-control" type="text"  required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类：</label>
            <div class="col-sm-8">
                <select name="categoryId" class="form-control m-b" th:with="type=${@dict.getType('bus_industry')}">
                    <option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}" required></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">品牌：</label>
            <div class="col-sm-8">
                <input name="brand" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">规格：</label>
            <div class="col-sm-8">
                <input name="spec" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">价格：</label>
            <div class="col-sm-8">
                <input name="price" class="form-control" type="number" required>
            </div>
        </div>

        <div class="form-group">
            <input type="hidden" name="goodsCover" id="goodsCover" value="goodsCover"/>
            <label class="col-sm-3 control-label"></label>
            <div id="uploadBtn" class="col-sm-8 fileinput fileinput-new" data-provides="fileinput">
        <span class="btn btn-outline-secondary btn-file">
            <span class="fileinput-new">
                <a class="btn btn-warning btn-sm" ><i class="fa fa-upload"></i>&nbsp;上传图片</a>
            </span>
            <input type="file" name="file"  id="bpmnInfoinition" multiple required>
        </span>
                <span class="fileinput-filename"></span>
                <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <input name="goodsDesc" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="common/include :: footer" />
<th:block th:include="common/include :: datetimepicker" />
<th:block th:include="common/include :: jasny-bootstrap" />
<script th:inline="javascript">
    var prefix = ctx + "/business/goods";
    $("#form-statement-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-statement-add').serialize());
        }
    }

    // 上传图片
    $('#bpmnInfoinition').on("change.bs.fileinput",function () {
        var file = $('#bpmnInfoinition')[0].files[0];
        var formData = new FormData();
        if (!file) {
            return;
        }
        formData.append("file",file);
        $.ajax({
            url: prefix + '/uploadFile',
            type:"POST",
            data:formData,
            processData: false,
            contentType: false,
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.operate.ajaxSuccess(result);
                    $("#goodsCover").val(result.data);
                }else {
                    $.modal.alertError(result.msg);
                }
            }
        })
    })

</script>
</body>
</html>